// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from "axios";
// 引入 ui 库
import ElementUI from 'element-ui';
// 引入 css
import 'element-ui/lib/theme-chalk/index.css';
//注册组件库
Vue.use(ElementUI);
// 绑定到原型
Vue.prototype.$axios = axios;

//设置默认的 api 域名
axios.defaults.baseURL = "http://111.230.181.206:3000"

Vue.config.productionTip = false
// 导航守卫
router.beforeEach((to, from, next)=>{
  if (to.path != '/login') {
    const token = localStorage.getItem('token');
    if (!token) {
      // 跳转到登录页
      router.push('/login');
    }else {
      next();
    }
  }else {
    next();
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
